package org.oos.dao;

import static org.oos.ApiUrlProvider.UserSites;

import org.oos.atom.MultimediaFeed;
import org.oos.atom.MultimediaFeedImpl;
import org.oos.atom.entries.MultimediaEntry;
import org.oos.atom.entries.MultimediaEntryImpl;
import org.oos.dao.lists.FullAccessDynamicList;

import com.google.api.client.http.GenericUrl;

public class MultimediaDaoImpl extends
		AbstractDao<MultimediaEntry, MultimediaFeed<MultimediaEntry>> implements
		MultimediaDao {
	
	private String userSlug;
	
	private String siteSlug;

	public MultimediaDaoImpl() {
		super(MultimediaFeedImpl.class, MultimediaEntryImpl.class);
	}

	@Override
	protected GenericUrl getEntryUrl(MultimediaEntry entry) {
		return getEntryUrl(entry.getFnv());
	}

	@Override
	protected GenericUrl getEntryUrl(String param) {
		if (userSlug != null && siteSlug != null) {
			return UserSites.getUrl(userSlug, siteSlug, "media", param + ".atom");
		} else {
			throw new IllegalStateException("There must be both slugs");
		}
	}

	@Override
	protected GenericUrl getFeedUrl() {
		if (userSlug != null && siteSlug != null) {
			return UserSites.getUrl(userSlug, siteSlug, "media");
		} else {
			throw new IllegalStateException("There must be both slugs");
		}
	}
	
	@Override
	protected GenericUrl getMediaUrl(MultimediaEntry entry) {
		return getMediaUrl(entry.getFnv());
	}

	@Override
	protected GenericUrl getMediaUrl(String param) {
		if (userSlug != null && siteSlug != null) {
			return UserSites.getUrl(userSlug, siteSlug, "media", param);
		} else {
			throw new IllegalStateException("There must be both slugs");
		}
	}

	@SuppressWarnings("unchecked")
	@Override
	protected FullAccessDynamicList<MultimediaEntry, MultimediaFeed<MultimediaEntry>> getList(MultimediaFeed feed) {
		return new FullAccessDynamicList<MultimediaEntry, MultimediaFeed<MultimediaEntry>>(this, feed);
	}

	@Override
	public void setUserSlug(String userSlug) {
		this.userSlug = userSlug;
	}

	@Override
	public void setSiteSlug(String siteSlug) {
		this.siteSlug = siteSlug;
	}

}
